#ifndef VPGUTS_H
#define VPGUTS_H

class Shue;
class ShueGameInfo;
class VPHand;
class CardMgr;
class VPokerSavedGame;
class VPConnection;

class VPGuts
{
	public:
		enum PayFreqType { LOW, MEDIUM, HIGH, CUSTOM, NUMFREQS };

		VPGuts(PayFreqType, int32* payTable, int32 maxCols, int32 maxEvents);
		virtual ~VPGuts();

		static VPGuts* getGuts(int32 ID, int32 whichPayFreq);

		int32 getPayFreq();

		virtual Shue* newShue(const ShueGameInfo &sgi) = 0;
		virtual CardMgr* getCardMgr() = 0;

		virtual void createSubGameData(uint8* subGameData, int32* length, int32 maxlength);
		virtual void restoreSubGameData(uint8* subGameData, int32* length);

		virtual void dealHand(Shue*, VPHand*);
		virtual void makeDealtHandForClient(VPHand*, VPHand*);
		virtual void rollbackDeal(Shue*, VPHand*);

		virtual bool8 isHoldTheseValid(uint8 held);

		virtual void drawHand(uint8 held, Shue*, VPHand*);
		virtual bool8 drawHandCheck(uint8*, uint8 held, Shue*, VPHand*);
		virtual void makeDrawnHandForClient(VPHand*, VPHand*);
		virtual void rollbackDraw(uint8 held, Shue*, VPHand*);

		enum CalcPayoutMode { DEALT_CARDS, DRAWN_CARDS };
		virtual int32 CalcPayout(int32* pEvent, VPHand* pHand, int32 bet,
			CalcPayoutMode, uint8* subGameData, int32 length) = 0;

		// dblUpCompare returns:
		//		> 0 : dealer card ranks higher
		//		  0 : player card has the same rank as the dealer card
		//		< 0 : player card ranks higher
		//
		virtual int32 doubleUpCompare(uint8 dealer, uint8 player);

		virtual void restoreHand(Shue*, VPHand*, VPokerSavedGame*);

		virtual uint8 restoreHeldCards(uint8* dealt, uint8* drawn, int32 num);

	protected:
		int32 PTBLENTRY(int32 col, int32 evt);

	protected:

		PayFreqType payFreq;

		int32*		payTable;
		int32		pt_maxCols;
		int32		pt_maxEvents;
};

inline
VPGuts::VPGuts(PayFreqType payFreq,
	int32* payTable, int32 maxCols, int32 maxEvents)
{
	this->payFreq = payFreq;
	this->payTable = payTable;
	this->pt_maxCols = maxCols;
	this->pt_maxEvents = maxEvents;
}

inline
VPGuts::~VPGuts()
{
}

inline int32
VPGuts::getPayFreq()
{
	return payFreq;
}

inline int32
VPGuts::PTBLENTRY(int32 col, int32 evt)
{
	return payTable[
		(((((int32)payFreq) * pt_maxCols) + col) * pt_maxEvents) + evt];
}

#endif
